package com.evaluation.kexingcp.psycho.evaluation.sys.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.evaluation.kexingcp.common.core.util.R;
import com.evaluation.kexingcp.common.excel.annotation.ResponseExcel;
import com.evaluation.kexingcp.common.log.annotation.SysLog;
import com.evaluation.kexingcp.psycho.evaluation.sys.entity.EvaluationWarningManualReviewEntity;
import com.evaluation.kexingcp.psycho.evaluation.sys.entity.EvaluationWarningRecordsEntity;
import com.evaluation.kexingcp.psycho.evaluation.sys.service.EvaluationWarningManualReviewService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 预警人工审核
 *
 * @author kexingcp
 * @date 2024-10-16 10:16:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/evaluationWarningManualReview" )
@Tag(description = "evaluationWarningManualReview" , name = "预警人工审核管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EvaluationWarningManualReviewController {

    private final EvaluationWarningManualReviewService evaluationWarningManualReviewService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param evaluationWarningManualReview 预警人工审核
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_view')" )
    public R getEvaluationWarningManualReviewPage(@ParameterObject Page page, @ParameterObject EvaluationWarningManualReviewEntity evaluationWarningManualReview) {
        LambdaQueryWrapper<EvaluationWarningManualReviewEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.like(!Objects.isNull(evaluationWarningManualReview.getUsername()), EvaluationWarningManualReviewEntity::getUserInfo,evaluationWarningManualReview.getUsername());
        return R.ok(evaluationWarningManualReviewService.page(page, wrapper));
    }


    /**
     * 通过id查询预警人工审核
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(evaluationWarningManualReviewService.getById(id));
    }

    /**
     * 新增预警人工审核
     * @param evaluationWarningManualReview 预警人工审核
     * @return R
     */
    @Operation(summary = "新增预警人工审核" , description = "新增预警人工审核" )
    @SysLog("新增预警人工审核" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_add')" )
    public R save(@RequestBody EvaluationWarningManualReviewEntity evaluationWarningManualReview) {
        return R.ok(evaluationWarningManualReviewService.save(evaluationWarningManualReview));
    }

    /**
     * 修改预警人工审核
     * @param evaluationWarningManualReview 预警人工审核
     * @return R
     */
    @Operation(summary = "修改预警人工审核" , description = "修改预警人工审核" )
    @SysLog("修改预警人工审核" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_edit')" )
    public R updateById(@RequestBody EvaluationWarningManualReviewEntity evaluationWarningManualReview) {
        return R.ok(evaluationWarningManualReviewService.updateById(evaluationWarningManualReview));
    }

    /**
     * 通过id删除预警人工审核
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除预警人工审核" , description = "通过id删除预警人工审核" )
    @SysLog("通过id删除预警人工审核" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(evaluationWarningManualReviewService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param evaluationWarningManualReview 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('admin_evaluationWarningManualReview_export')" )
    public List<EvaluationWarningManualReviewEntity> export(EvaluationWarningManualReviewEntity evaluationWarningManualReview,Long[] ids) {
        return evaluationWarningManualReviewService.list(Wrappers.lambdaQuery(evaluationWarningManualReview).in(ArrayUtil.isNotEmpty(ids), EvaluationWarningManualReviewEntity::getId, ids));
    }
}